<template>
  <div class="page has-navbar" v-nav="{ title: '商品详情', showBackButton: true, onBackButtonClick: back }">
    <div class="page-content text-center">
      <div class="banner">
        <swiper direction="horizontal"
                height="193">
          <swiper-item>
            <img src="../image/2.png" alt="">
          </swiper-item>
        </swiper>
      </div>
      <div class="detailsContent">
        <h1 class="title">玫瑰花束 玫瑰花 爱情的精灵！</h1>
        <p class="tbtx">特别提醒：此鲜花由于制作时间较长，请提前 5 小时下单！</p>
        <p class="xxqk">
          <span><img src="../image/_ionicons_svg_ios-cube.svg">库存 </span>
          <span><img src="../image/_ionicons_svg_md-trending-up.svg" alt="">销量 </span>
          <span><img src="../image/_ionicons_svg_md-trending-up.svg" alt="">三环内免费配送 </span>
        </p>
        <div class="price">
          <div class="priceNumber">
            <span class="miniFont">￥</span><span class="priceInt">45</span><span class="miniFont">.50</span>
          </div>
          <div class="peiSong">
            <div class="li">新鲜采摘</div>
            <div class="li">支付保证</div>
            <div class="li">配送保证</div>
          </div>
        </div>
      </div>
      <div class="shoppDetails">
        <h1 class="title">商品详情</h1>
        <div class="imgList">
          <div class="li">
            <img src="../image/3.png" alt="">
            <img src="../image/4.png" alt="">
            <img src="../image/5.png" alt="">
            <img src="../image/3.png" alt="">
          </div>
        </div>
      </div>

    </div>
    <div class="buttonMenu">
      <div class="kefu">
        <div>
          <p><i class="icon ion-headphone"></i></p>
          <p>客服</p>
        </div>
      </div>
      <div class="joinCat" @click="showCustomPopup">
        加入购物车
      </div>
      <div class="buy" @click="buy">
        立即购买
      </div>
    </div>
    <div id="floatCart" @click="joinCart">
      <i class="icon ion-ios-cart"></i>
    </div>
    <ShopSpec class="shopSpec"></ShopSpec>

  </div>
</template>

<script>
  import ShopSpec from '../components/ShopSpec'
    export default {
        name: "Details",
        data(){
            return{
              joinCartFlag : true,
            }
        },
        components : {
          ShopSpec
        },
        methods: {
          back(){
            $router.go(-1)
          },
          joinCart(){
            $toast.show('已加入购物车');
          },
          showCustomPopup() {
            this.joinCarts(()=>{
              let options = {
                effect: 'scale',
                title: '',
                buttons: [
                  {text: '我晓得了'},
                  // {text: '取消'},
                ]
              };
              let popup = $popup.fromTemplate('<div style="margin-bottom: 0; text-align: center;"><h3>加入成功</h3><p>商品已加入购物车了</p></div>', options);
              popup.show().then((buttonIndex) => {
                if (buttonIndex === 0)
                  console.log('确定加入购物车后的回调')
              })
            });
          },
          joinCarts(callback){
            let $shopSpec = document.getElementsByClassName('shopSpec');

            if (this.joinCartFlag) {
              $shopSpec[0].setAttribute('style' , 'transform:translateY(0px);opacity : 1');
              console.log($shopSpec);
            }else {
              $shopSpec[0].setAttribute('style' , 'transform:translateY(100vh);opacity : 0');
              callback();
            }
            this.joinCartFlag = !this.joinCartFlag;
          },
          buy(){
            this.joinCarts(()=>{
              $toast.show('正在跳转到购买页面');
            });
          }
        }
    }
</script>

<style scoped lang="less">
  @titleFontSize : 18px;
  @minFontSize : 12px;
  @pricColor : #ff3300;
  //规格
  .shopSpec{
    position: absolute;
    bottom: 0;
    z-index: 999;
    background: rgba(0 , 0 , 0 ,.5);
    transform: translateY(100vh);
    transition: .4s;
    opacity: 0;
  }
  .banner{
    img{
      width: 100%;
    }
  }
  .title{
    font-size: @titleFontSize;
  }
  .detailsContent{
    padding: 15px;
    text-align: start;
    background: #ffffff;
    .tbtx{
      color: @pricColor;
      font-size: 12px;
    }
    .xxqk{
      color: #999999;
      font-size: @minFontSize;
      img{
        margin: 0;
        width: @minFontSize;
        height: @minFontSize;
      }
      span{
        margin-right: 15px;
      }
    }
    .price{
      color: @pricColor;
      display: flex;
      justify-content: space-between;
      .priceInt{
        font-size: 36px;
      }
      .miniFont{
        font-size: 24px;
      }
      .peiSong{
        display: flex;
        color: #ed8f03;
        .li{
          margin-left: 15px;
          padding: 2px;
          border: 1px solid #ed8f03;
          border-radius: 2px;
        }
      }
    }
  }
  .shoppDetails{
    background: #ffffff;
    margin-top: 10px;
    margin-bottom: 50px;
    .title{
      position: relative;
      text-align: start;
      padding-left: 20px;
      &::before{
        content: '';
        width: 10px;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
        background: #ed8f03;
      }
    }
    .imgList{
      img{
        width: 100%;
      }
    }
  }
  .buttonMenu{
    position: absolute;
    bottom: 0;
    z-index: 999;
    width: 100%;
    display: flex;
    justify-content: space-around;
    font-size: 18px;
    text-align: center;
    .kefu{
      width: 30%;
      background: #ffffff;
      line-height: 0;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    .joinCat,.buy{
      background: #ff3300;
      width: 35%;
      color: #ffffff;
      font-weight: bold;
      line-height: 50px;
    }
    .buy{
      background: #ef2b67;
    }
  }
  //悬浮购物车
  #floatCart{
    background: seagreen;
    width: 50px;
    height: 50px;
    position: absolute;
    color: white;
    line-height: 50px;
    text-align: center;
    left: 15px;
    bottom: 100px;
    font-size: 30px;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
    background: rgba(0 , 0, 0, .5);
  }
</style>
